home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 1.iso / ARGONET / PD / PROGRAMMING / DESKLIBC / SOURCES.ZIP / DeskLib / !DLSources / Libraries / Icon / c / GetText < prev    next >
Text File  |  1995-07-29  |  2KB  |  65 lines

  1. /*
  2.     ####             #    #     # #
  3.     #   #            #    #       #          The FreeWare C library for 
  4.     #   #  ##   ###  #  # #     # ###             RISC OS machines
  5.     #   # #  # #     # #  #     # #  #   ___________________________________
  6.     #   # ####  ###  ##   #     # #  #                                      
  7.     #   # #        # # #  #     # #  #    Please refer to the accompanying
  8.     ####   ### ####  #  # ##### # ###    documentation for conditions of use
  9.     ________________________________________________________________________
  10.  
  11.     File:    Icon.GetText.c
  12.     Author:  Copyright © 1992, 1993, 1994 Jason Williams
  13.     Version: 1.02 (22 May 1994)
  14.     Purpose: Retrieves the text/spritename from an icon
  15.     Mods:    29 Jul 1995 JPS - now sets terminter in returned string
  16.                                rather than the icon's buffer.
  17. */
  18.  
  19. #include "DeskLib:Wimp.h"
  20. #include "DeskLib:WimpSWIs.h"
  21. #include "DeskLib:Icon.h"
  22.  
  23. #include <string.h>
  24.  
  25.  
  26. extern void Icon_GetText(window_handle w, icon_handle i, char *text)
  27. /*
  28.  * Copies the text string from the icon (sprite name, text, or indirected)
  29.  * into the array pointed to by "text"
  30.  */
  31. {
  32.   icon_block istate;
  33.   char       *buffer;
  34.   int        len = wimp_MAXNAME;
  35.   int        index;
  36.  
  37.   text[0] = 0;  /* return NULL string if anything goes wrong */
  38.  
  39.   Wimp_GetIconState(w, i, &istate);
  40.   if (istate.flags.data.indirected)
  41.   {
  42.     if (istate.flags.data.sprite)
  43.         buffer = (char *) istate.data.indirectsprite.name;
  44.     else
  45.     {
  46.       buffer = istate.data.indirecttext.buffer;
  47.       len    = istate.data.indirecttext.bufflen;
  48.     }
  49.   }
  50.   else
  51.     buffer = istate.data.text;                           /* text/sprite name */
  52.  
  53.   strncpy(text, buffer, len);                            /* text/sprite name */
  54.   
  55.   /* Terminate string at first control character, or at end of buffer */
  56.   index = 0;
  57.   while ((index < len) && (text[index] >= ' '))
  58.     index++;
  59.     
  60.   if (index < len)
  61.     text[index] = NULL;
  62.   else
  63.     text[len - 1] = NULL;
  64. }
  65.